/*
visqrt
Copyright (C) 2010  Bhupendra Aole

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
*/
/*
 * File: PerlinNoise.java
 * Author: Bhupendra Aole
 * Date: Aug 29, 2010: 
 * 
 * Revisions:
 * ----------
 */

package aole.texture;

import aole.math.Color3;
import aole.math.Vec3;
import aole.math.noise.Perlin;

/**
 * 
 */
public class PerlinNoise implements Texture3 {

	public Color3 color1 = new Color3(Color3.WHITE);
	public Color3 color2 = new Color3(Color3.BLACK);
	public float level = 15f;

	/* (non-Javadoc)
	 * @see aole.texture.Texture3#getColor(aole.math.Vec3)
	 */
	public Color3 getColor (Vec3 ip) {
		float coef = (float) Math.abs((Perlin.noise(level * ip.x, level * ip.y,
				level * ip.z)));
		Color3 c = new Color3();
		c.r = color1.r * coef + color2.r * (1 - coef);
		c.g = color1.g * coef + color2.g * (1 - coef);
		c.b = color1.b * coef + color2.b * (1 - coef);

		return c;
	}

	public void readcolor1 (String s) {
		color1.read(s);
	}

	public void readcolor2 (String s) {
		color2.read(s);
	}
}
